﻿using System;
using System.Web.UI;

namespace Batik.Web.UI.Controls
{
    public class DataViewItem : Control, IDataItemContainer
    {
        public override string ClientID
        {
            get
            {
                return String.Format("{0}_{1}", Parent.ClientID, base.ClientID);
            }
        }
        protected override void Render(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
            if (IsClientTemplate)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "sys-template");
            }
            writer.RenderBeginTag(TemplateContainerTag);
            base.Render(writer);
            writer.RenderEndTag();
        }

        public DataViewItem(object dataItem, int index)
        {
            DataItem = dataItem;
            DataItemIndex = DisplayIndex = index;
        }
        internal bool IsClientTemplate { get; set; }
        [PersistenceMode(PersistenceMode.Attribute)] 
        internal HtmlTextWriterTag TemplateContainerTag { get; set; }
        #region IDataItemContainer Members
        public object DataItem { get; private set;}
        public int DataItemIndex {get; private set; }
        public int DisplayIndex { get; private set;}
        #endregion
    }
}
